package controllers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import models.cms.Post;
import models.cms.Resource;
import models.cms.Tag;
import models.sys.User;
import play.data.Upload;
import play.db.jpa.JPABase;
import swagger.annotations.Param;
import utils.ResourceUtils;
import utils.SessionUtils;

public class App extends SController {

    public static void register() {
        render("/public/regist.html");
    }

    public static void login() {
        render("/public/login.html");
    }

    public static void logout() {
        SessionUtils.clear();
        home();
    }

    public static void index() {
        render();
    }

    public static void home() {
        List<Post> posts = Post.find("to_post is null order by created_at desc").fetch(20);
        render("/public/home.html", posts);
    }

    public static void tag(String tagname) {
        List<Post> posts = Post.find("select p from models.cms.Post p " +
                "join p.tags t " +
                "where  p.to_post is null and t.name = ? order by p.created_at desc"
                ,tagname
        ).fetch(20);
        render("/public/home.html", posts);
    }

    public static void compose() {
        render("/public/faBuZiLiao.html");
    }

    public static void view_post(long id) {
        Post post = Post.findById(id);
        render("/public/ziLiaoXiangQing.html", post);
    }

    public static void user(long id) {
        User user = User.findById(id);
        render("/public/geRenZhongXin.html",user);
    }
    public static void user_info(long id) {
        User user = User.findById(id);
        render("user-info.html",user);
    }
}
